package 中介模式

import "fmt"

type Mediator interface {
	Communicate(to string)
}

type agentSetter interface {
	setAgent(mediator Mediator)
}

type host struct {
	mediator Mediator
}

func (h *host) setAgent(mediator Mediator) {
	h.mediator = mediator
}
func (h *host)Talk()  {
	fmt.Println("Hi guest")
	h.mediator.Communicate("host")
}
type guest struct {
	mediator Mediator
}

func (g *guest) setAgent(mediator Mediator) {
	g.mediator =  mediator
}

func (g *guest)Talk()  {
	fmt.Println("Hi host")
	g.mediator.Communicate("guest")
}


type foo struct {
	name string
	host
	guest
}

func (f *foo)	Communicate(to string)  {
	switch to {
	case "host":
		fmt.Println("房东你好")
	case "guest":
		fmt.Println("小弟弟你是来租房子的吗")
	}
}

func NewAgentAndBind(name string) *foo {
	out := new(foo)
	out.name = name
	out.host = host{out}
	out.guest = guest{out}
	return  out
}